package com.christian.singleton;

/**
 * 文件描述：单例模式，静态内部类：加载外部类时不会加载内部类，这样可以实现懒加载
 *
 * @Author：wang
 * @Date：2020-02-27 10:22:11
 */
public class StaticInnerClassSingleton {

    /**
     * 构造方法私有化
     */
    private StaticInnerClassSingleton() {

    }

    /**
     * 静态内部类实例化对象
     */
    private static class InnerClass {
        private static final StaticInnerClassSingleton INSTANCE = new StaticInnerClassSingleton();
    }

    /**
     * 获取对象实例方法
     *
     * @return
     */
    public static StaticInnerClassSingleton getInstance() {
        return InnerClass.INSTANCE;
    }

    public static void main(String[] args) {
        StaticInnerClassSingleton instance1 = getInstance();
        StaticInnerClassSingleton instance2 = getInstance();

        System.out.println("两个对象实例是否相同：" + (instance1 == instance2));
    }
}
